package com.shop.common.model.param.user;

import com.shop.common.entity.user.UserPayLog;
import com.shop.common.util.DateUtil;
import com.shop.common.util.state.DataStatus;
import lombok.Data;

import java.math.BigDecimal;

/**
 * @Description:
 *
 * @author zhoulk
 * @date: 2019年04月15日  10:53
 */
@Data
public class UserPayLogInput extends UserPayLog {
    public static UserPayLogInput newUserPayLog(Integer userId, BigDecimal balance, BigDecimal beforBalance, Integer integral, Integer beforIntegral, Integer logType, Integer modType, String comment) {
        UserPayLogInput userPayLogInput = new UserPayLogInput();
        userPayLogInput.setUserId(userId);
        if (balance != null && beforBalance != null) {
            userPayLogInput.setBalance(balance);
            userPayLogInput.setBeforBalance(beforBalance);
            userPayLogInput.setAfterBalance(modType==1?beforBalance.add(balance):beforBalance.subtract(balance));
        }
        if (integral != null && beforIntegral != null) {
            userPayLogInput.setIntegral(integral);
            userPayLogInput.setBeforIntegral(beforIntegral);
            userPayLogInput.setAfterIntegral(modType==1?beforIntegral + integral:beforIntegral - integral);
        }
        userPayLogInput.setLogType(logType);
        userPayLogInput.setModType(modType);
        userPayLogInput.setComment(comment);
        userPayLogInput.setCreateTime(DateUtil.newNowDate());
        userPayLogInput.setDataStatus(DataStatus.USE.value());
        return userPayLogInput;
    }

    public static UserPayLogInput newUserPayLog(Integer userId, BigDecimal balance, BigDecimal beforBalance, Integer modType, String comment) {
        return newUserPayLog(userId, balance, beforBalance, null, null, 1, modType, comment);
    }

    public static UserPayLogInput newUserPayLog(Integer userId, Integer integral, Integer beforIntegral, Integer modType, String comment) {
        return newUserPayLog(userId, null, null, integral, beforIntegral, 2, modType, comment);
    }

    private Integer page;
    private Integer pageSize;
}
